package cn.tedu.jdbc;

import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

/**
 * DBUtil工具类测试;
 */
public class JDBCDemo4 {
    public static void main(String[] args) {
        try {
            //创建数据库连接对象[利用工具类]
            Connection connection = DBUtil.getConnection();
            Statement statement = connection.createStatement();
            //用户输入
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入用户名:");
            String username = scanner.nextLine();
            //SQL:字符串拼接方式执行SQL
            String sql = "DELETE FROM userinfo WHERE username='"+username+"'";
            //i:受影响的数据条数
            int i = statement.executeUpdate(sql);
            if (i > 0){
                System.out.println("注销成功");
            }else {
                System.out.println("注销失败");
            }
            //断开连接
            connection.close();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}









